﻿@namespace Microsoft.FluentUI.AspNetCore.Components
@inherits FluentComponentBase

<div id="@Id" class="@ClassValue" style="@StyleValue" top-corner="@TopCorner"
     @onclick="@(e => PopoverVisible = !PopoverVisible)">
    @StartTemplate
    <FluentPersona Id="@PersonaId"
                   Image="@Image"
                   Name="@FullName"
                   ImageSize="@ButtonSize"
                   Status="@Status"
                   StatusTitle="@StatusTitle"
                   Initials="@Initials"
                   Style="height: inherit;" />
    @EndTemplate
</div>

<FluentPopover AnchorId="@PersonaId"
               Class="@PopoverClass"
               Style="@PopoverStyle"
               HorizontalPosition="@HorizontalPosition.Start"
               @bind-Open="@PopoverVisible"
               @attributes="@AdditionalAttributes">
    <Header>
        @if (HeaderTemplate is null && (!string.IsNullOrEmpty(HeaderLabel) || !string.IsNullOrEmpty(HeaderButton)))
        {
            <FluentStack VerticalAlignment="@VerticalAlignment.Center">
                @if (!string.IsNullOrEmpty(HeaderLabel))
                {
                    <FluentLabel part="header-label">@HeaderLabel</FluentLabel>
                }
                @if (!string.IsNullOrEmpty(HeaderButton))
                {
                    <FluentSpacer />
                    <FluentButton part="header-button" Appearance="@Appearance.Stealth" OnClick="@OnHeaderButtonClick">@HeaderButton</FluentButton>
                }
            </FluentStack>
        }
        else
        {
            @HeaderTemplate
        }
    </Header>

    <Body>
        @if (ChildContent is null)
        {
            <FluentStack Style="height: 100%;">
                <FluentPersona Image="@Image"
                               ImageSize="@ImageSize"
                               Initials="@Initials"
                               Style="align-items: normal;">
                    <FluentLabel part="fullname" Typo="@Typography.Header" Style="font-weight: bold;">@FullName</FluentLabel>
                    <FluentLabel part="email">@EMail</FluentLabel>
                </FluentPersona>

            </FluentStack>
        }
        else
        {
            @ChildContent
        }
    </Body>

    <Footer>
        @if (FooterTemplate is null && !string.IsNullOrEmpty(FooterLink))
        {
            <FluentStack VerticalAlignment="@VerticalAlignment.Center">
                @if (!string.IsNullOrEmpty(FooterLabel))
                {
                    <FluentLabel part="footer-label">@FooterLabel</FluentLabel>
                }
                @if (!string.IsNullOrEmpty(FooterLink))
                {
                    <FluentSpacer />
                    <FluentAnchor part="footer-link" Appearance="@Appearance.Hypertext" Href="#" OnClick="@OnFooterLinkClick">@FooterLink</FluentAnchor>
                }
            </FluentStack>
        }
        else
        {
            @FooterTemplate
        }
    </Footer>
</FluentPopover>
